package com.liunian.test;

import com.liunian.algorithmstudy.tree.TreeNode;

public class MinCameraCover968 {

	int res = 0;
	public int minCameraCover(TreeNode root) {
		if (travelsal(root) == 0) {
			res++;
		}
		return res;
	}

	private int travelsal(TreeNode root) {
		if (root == null) {
			return 2;
		}
		int left = travelsal(root.left);
		int right = travelsal(root.right);
		if (left == 2 && right == 2) {
			return 0;
		} else if (left == 0 || right == 0) {
			res++;
			return 1;
		} else {
			return 2;
		}
	}

}
